Find a data set on Transportation and create one interactive plot using plotly. All of your axes, titles, subtitles, and captions must be labeled and all of the visualizations must be colorful and easy to read.
#install.packages("plotly")
#install.packages("htmlwidgets")
library(plotly)
Loading required package: ggplot2
RStudio Community is a great place to get help:
https://community.rstudio.com/c/tidyverse
Registered S3 methods overwritten by 'htmltools':
method from
print.html tools:rstudio
print.shiny.tag tools:rstudio
print.shiny.tag.list tools:rstudio
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
packageVersion('plotly')
[1] ‘4.9.3’
flights <- read.csv("~/Downloads/feb-20-us-flight-delay.csv")
View(flights)
summary(flights)
MONTH DAY_OF_MONTH DAY_OF_WEEK
Min. :2 Min. : 1.00 Min. :1.000
1st Qu.:2 1st Qu.: 8.00 1st Qu.:2.000
Median :2 Median :15.00 Median :4.000
Mean :2 Mean :15.18 Mean :3.989
3rd Qu.:2 3rd Qu.:22.00 3rd Qu.:6.000
Max. :2 Max. :29.00 Max. :7.000
OP_UNIQUE_CARRIER ORIGIN
Length:574268 Length:574268
Class :character Class :character
Mode :character Mode :character
DEST DEP_TIME DEP_DEL15
Length:574268 Min. : 1 Min. :0.000
Class :character 1st Qu.: 918 1st Qu.:0.000
Mode :character Median :1328 Median :0.000
Mean :1333 Mean :0.144
3rd Qu.:1741 3rd Qu.:0.000
Max. :2400 Max. :1.000
NA's :4938 NA's :4951
DISTANCE X
Min. : 31.0 Mode:logical
1st Qu.: 369.0 NA's:574268
Median : 641.0
Mean : 795.7
3rd Qu.:1036.0
Max. :5095.0
originflights <- flights %>% group_by(DAY_OF_WEEK) %>% summarise(Avg = mean(DISTANCE))
`summarise()` ungrouping output (override with `.groups` argument)
a <- ggplot(originflights, aes(x = DAY_OF_WEEK, y = Avg, fill = DAY_OF_WEEK)) +
geom_bar(stat = "identity") +
theme(legend.position = "none") +
labs(title = "Average Distance of Days of Week",
subtitle = "The graph shows the average flight distance of every day of the week",
x = "Days of the Week",
y = "Average Distance")
a
ggplotly(a)